package com.example.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dto.systemmanagement.hospital.HospitalUpdateDTO;
import com.example.entity.Hospital;
import com.example.service.IHospitalService;
import com.example.vo.JsonVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author diandian
 * @since 2024-04-07
 */
@RestController
@RequestMapping("/system/hospital")
@Api(tags = "hospital")
public class HospitalsController {
    @Autowired
    IHospitalService hospitalService;

    /**
     * 医院信息查询
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/list")
    public JsonVO<List<Hospital>> searchHospital(@RequestParam long current, @RequestParam long size){
        IPage<Hospital> page= new Page<>(current,size);
        return JsonVO.success(hospitalService.list(page));
    }

    /**
     * 医院信息添加
     * @param hospital
     * @param userId
     * @return
     */
    @PostMapping("/insert")
    public JsonVO<?> addHospital(@RequestBody Hospital hospital, @RequestHeader("userId") String userId){
        if(hospitalService.add(hospital,userId)){
            return JsonVO.success(true);
        }else {
            return JsonVO.fail(false);
        }

    }

    /**
     * 医院信息删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public JsonVO<?> deleteHospital(@RequestParam String id){
        if(hospitalService.removeById(id)){
            return JsonVO.success(true);
        }else {
            return JsonVO.fail(false);
        }
    }

    /**
     * 医院信息修改
     * @param dto
     * @param userId
     * @return
     */
    @PostMapping("/update")
    public JsonVO<?> updateHospital(@RequestBody HospitalUpdateDTO dto,@RequestHeader("userId") String userId){
        if(hospitalService.update(dto,userId)){
            return JsonVO.success(true);
        }else {
            return JsonVO.fail(false);
        }
    }

}

